#include "porting.h"
#include "inifile.h"
#include "errorcode.h"
#include "lnstring.h"
#include "lnthread.h"
#include "fileio.h"

#include <stdio.h>

static int 
ini_is_section (const char* line, const char* section)
{
  return 0;
};

static  int
ini_delete_section (const char * file_name, const char* section )
{
  char** lines;
  struct respool_t respool;
  char respool_buffer[16*1024];
  FILE* fd = NULL;

  respool_init(respool, respool_buffer, NULL);

  lines = read_lines (file_name, &respool);

  if (lines == NULL)
  {
    goto cleanup;
  };

  fd = fopen (file_name,"w");

  if (fd == NULL)
  {
    er_set (NULL, LN_ER_FILE_OPEN_FAILED, file_name, "w");
    goto cleanup;
  };

  for(;*lines;lines++)
  {
    
  };

cleanup:;
  respool_close (&respool);

  if (fd)
  {
    fclose (fd);
  };

  return 0;
};


int 
ini_write (
    const char* file_name,
    const char* section,
    const char* key,
    const char* value )
{
  if (file_name == NULL || *file_name == 0 || 
      section == NULL || *section == 0 )
  {
    er_set (NULL, LN_ER_PARAMETER_INVALID);
    return LN_ER_PARAMETER_INVALID;
  };

  if ( key == NULL || *key == 0 )
  {
    return ini_delete_section (file_name, section);
  };

  return 0;
};

int 
ini_read_section_list (
    const char* file_name,
    char* buf,
    int   buf_size )
{
  return 0;
}

int 
ini_read_key_list (
    const char* file_name,
    const char* section,
    char* buf,
    int   buf_size )
{
  return 0;
};

const char* 
ini_read_string (
    const char* file_name,
    const char* section,
    const char* key,
    const char* def,
    char* buf,
    int buf_size )
{

  return def;
};

int 
ini_read_integer (
    const char* file_name,
    const char* section,
    const char* key,
    int def )
{
   char buf[64];

   if ( ini_read_string (file_name, section, key, NULL, buf, sizeof(buf)) == NULL )
   {
     return def;
   }

   return atoi (buf);
};
